<?php
	include(CMS_DIR . "/model/" . $model . ".class.php");
	/**
	*用户管理控制模块
	**/
	class Admin {
		// 构造函数
		public function __constract(){
		}

		// 用户列表
		public function userlist($data){
			// 验证类型值范围
			if(!valifyRange($data->type, array(0, 1))){
				returnAjaxJson(400, "type格式错误", null);
			}

			$adminObj = new AdminClass();
			$userList = $adminObj->getList($data);
			returnAjaxJson(200, "操作成功！", $userList);
		}

		// 添加用户
		public function add($data){
			// 验证用户名
			if(!valifyUserName($data->name)){
				returnAjaxJson(400, "用户名格式错误！", null);
			}

			// 验证邮箱
			if(!valifyEmail($data->email)){
				returnAjaxJson(400, "邮箱格式错误！", null);
			}

			// 验证类型值范围
			if(!valifyRange($data->type, array(0, 1))){
				returnAjaxJson(400, "用户类型格式错误！", null);
			}

			// 验证roleid整数类型
			if(!is_int($data->roleId)){
				returnAjaxJson(400, "角色组格式错误！", null);
			}

			$adminObj = new AdminClass();
			$userList = $adminObj->add($data);
			returnAjaxJson(200, "操作成功！", null);
		}

		// 删除用户
		public function del($data){
			// 验证id整数类型
			if(!is_int($data->id)){
				returnAjaxJson(400, "用户id格式错误！", null);
			}

			$adminObj = new AdminClass();
			$adminObj->del($data);
			returnAjaxJson(200, "操作成功！", null);
		}

		// 启用、禁用用户
		public function enable($data){
			// 验证flag类型值范围
			if(!valifyRange($data->flag, array(0, 1))){
				returnAjaxJson(400, "flag类型格式错误！", null);
			}

			// 验证id整数类型
			if(!is_int($data->id)){
				returnAjaxJson(400, "用户id格式错误！", null);
			}

			$adminObj = new AdminClass();
			$adminObj->enable($data);
			returnAjaxJson(200, "操作成功！", null);
		}

		// 修改用户密码
		public function pwd($data){
			$adminObj = new AdminClass();
			$adminObj->pwd($data);
			returnAjaxJson(200, "修改密码成功！", null);
		}

		// 编辑用户信息
		public function edit($data){
			// 验证用户名
			if(!valifyUserName($data->name)){
				returnAjaxJson(400, "用户名格式错误！", null);
			}

			// 验证邮箱
			if(!valifyEmail($data->email)){
				returnAjaxJson(400, "邮箱格式错误！", null);
			}

			// 验证类型值范围
			if(!valifyRange($data->type, array(0, 1))){
				returnAjaxJson(400, "用户类型格式错误！", null);
			}

			// 验证roleid整数类型
			if(!is_int($data->roleId)){
				returnAjaxJson(400, "角色组格式错误！", null);
			}

			// 验证roleid整数类型
			if(!is_int($data->id)){
				returnAjaxJson(400, "用户id格式错误！", null);
			}

			$adminObj = new AdminClass();
			$adminObj->edit($data);
			returnAjaxJson(200, "操作成功！", null);
		}

		// 获取用户菜单列表
		public function getmenu(){
			global $session;
			$adminObj = new AdminClass();
			$menuList = $adminObj->getMenu();
			$sessionMenuList = array();

			// session保存菜单
			$len = count($menuList);
			for($i=0; $i<$len; $i++){
				$item = $menuList[$i];
				$sessionMenuList[$item['url']] = $item;
			}
			$session->set("menuList", serialize($sessionMenuList));

			returnAjaxJson(200, "操作成功！", $menuList);
		}
	}
?>